package handler;

import java.util.List;
import java.util.Map;

import com.hn.comm.excel.ExcelHandler;
import com.hn.comm.excel.ExcelModel;
import com.hn.shoutchinese.pinying.service.impl.PinyingServiceImpl;
import com.hn.shoutchinese.sentence.model.SentenceCombin;
import com.hn.shoutchinese.sentence.service.impl.SentenceServiceImpl;

public class SentanceHandler extends BaseHandler {

	public void startWork() {
		SentanceHandler ph = new SentanceHandler();

		SentenceServiceImpl ss = new SentenceServiceImpl();

		ExcelModel eModel = ExcelHandler.getExcelData(BaseHandler
				.getExcelFile());

		// 得到单个
		int iCount = 0;
		for (Map<String, String> map : eModel.getContent()) {
			iCount++;
			// 得到例句
			String sentance1 = map.get(HEAD_CHINESE_SENTANCE1);
			// sentance1 = sentance1.trim();
			System.out.println("当前第" + iCount + "个，寻找相关("
					+ map.get(HEAD_CHINESE) + ")的例句.");
			if (sentance1 == null || sentance1.equals("null")
					|| sentance1.equals("")) {
				// 得到中文
				String chinese = map.get(HEAD_CHINESE);
				// 得到英文
				String english = map.get(HEAD_ENGLISH);

				// 得到例句
				List<SentenceCombin> sentanceCombins = ss.getSentences(chinese,
						english, 3);

				map.put(HEAD_CHINESE_SENTANCE1, sentanceCombins.get(0)
						.getTranSen());
				map.put(HEAD_ENGLISH_SENTANCE1, sentanceCombins.get(0)
						.getSourceSen());
				map.put(HEAD_CHINESE_SENTANCE2, sentanceCombins.get(1)
						.getTranSen());
				map.put(HEAD_ENGLISH_SENTANCE2, sentanceCombins.get(1)
						.getSourceSen());
				map.put(HEAD_CHINESE_SENTANCE3, sentanceCombins.get(2)
						.getTranSen());
				map.put(HEAD_ENGLISH_SENTANCE3, sentanceCombins.get(2)
						.getSourceSen());
			}
		}

		ExcelHandler.writeExcel(eModel, BaseHandler.getExcelFile());
		System.out.println("例句下载完成。。。。。");
	}

	public static void main(String[] args) {
		SentanceHandler ph = new SentanceHandler();
		ph.startWork();
	}
}
